package com.cctc.mychat.common.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.handler.timeout.IdleStateHandler;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.TimeUnit;

public class ReaderIdleStateHandler extends IdleStateHandler {
    private long readerIdleTime;

    public ReaderIdleStateHandler(long readerIdleTime) {
        super(readerIdleTime, 0, 0, TimeUnit.SECONDS);
        this.readerIdleTime = readerIdleTime;
    }

    @Override
    protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception {
        System.err.println(readerIdleTime + " 秒未读到数据，关闭连接！！！");
        ctx.channel().close();
    }
}
